from email.header import Header
from email.message import EmailMessage
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from smtplib import SMTP

from networkx.convert_matrix import to_pandas_adjacency

fromAddr = 'caoyangyang@zhi-zai.cn'
password = 'Zhizaithomas0'

toAddr = '1076760287@qq.com'

smtpServer = 'smtp.exmail.qq.com'



msg = MIMEMultipart()

body = """
<h3>Hi，all</h3>
<p>附件为本次FM_自动化测试报告。</p>
<p>请解压zip，并使用Firefox打开index.html查看本次自动化测试报告结果。</p>
<br><img src="cid:cat"></br> 
"""

msg['Subject'] = Header('smtp from zhizai', 'utf-8').encode()
msg['From'] = fromAddr
msg['To'] =toAddr
# mailBody = MIMEText(boby,_subtype='html', _charset='utf-8')
# msg.attach(mailBody)
# body = 'this is test an image'

msg.attach(MIMEText(body, 'html', 'utf-8'))

with open('./cat.jpg', 'rb') as image:
    imageData = image.read()
# msg.add_attachment(imageData, maintype='image',subtype='jpg')
#创建image对象
image = MIMEImage(imageData)
image.add_header('Content-ID', '<cat>')
msg.attach(image)

server =  SMTP(smtpServer, 25)
server.set_debuglevel(1)
server.login(fromAddr, password)

server.sendmail(fromAddr,[toAddr], msg.as_string() )
server.quit()